package logic

import (
	"context"
	"fmt"
	"shop/cache"
	"shop/shoprpc/internal/svc"
	"shop/shoprpc/shoprpc"
	"time"

	"github.com/zeromicro/go-zero/core/logx"
)

type SendSmsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSendSmsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendSmsLogic {
	return &SendSmsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SendSmsLogic) SendSms(in *shoprpc.SendSmsRequest) (*shoprpc.SendSmsResponse, error) {
	// todo: add your logic here and delete this line

	if l != nil {
		return nil, fmt.Errorf("短信最多发送 5 次/小时")
	}

	cache.Rdb.Set(l.ctx, "tel"+in.Tel, in.Tel, time.Minute*5)

	return &shoprpc.SendSmsResponse{}, nil

}
